<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<% request.setCharacterEncoding("UTF-8"); %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>正表查询数据</title>
    <meta charset="UTF-8">
</head>
<body>
<%!
    ResultSet rs;//保存查询的结果
%>
<%
    String no = request.getParameter("stuNo");
    String name = request.getParameter("stuName");//姓名输入框里的值
    System.out.println(name);
    String dbname = "goods";//数据库名称
    String username = "root";//数据库用户名
    String password = "1234";//数据库密码
    String url = "jdbc:mysql://localhost:3306/" + dbname;
//    Class.forName("com.mysql.jdbc.Driver");//mysql 5.7一下的版本
    Class.forName("com.mysql.cj.jdbc.Driver");//mysql 8.0
    Connection connection = DriverManager.getConnection(url, username, password);
    Statement statement = connection.createStatement();
    rs = statement.executeQuery("SELECT * FROM student where stu_no like " +
            "'%" + no + "%'  and stu_name LIKE '%" + name + "%'");//执行查询语句的地方
%>
<table border="1">
    <%
        while (rs.next()) {//判断数据是否已经显示完了
    %>
    <%--    一行--%>
    <tr>
        <%--        rs.getString("stu_no")--%>

        <form action="delete.jsp">
<%--                visibility: hidden 隐藏--%>
            <input value="<%=rs.getString(1)%>" name="stu_no" style="visibility: hidden">
            <td><button type="submit" style="width: 60px">删除</button></td>
        </form>
        <form action="edit.jsp">

         <td><button type="submit" style="width: 60px">编辑</button></td>
        <%
            for (int i = 1; i < 16; i++) {
                if (i == 1) {//表示当前列是学号，学号不用修改
        %>
        <td><input value="<%=rs.getString(i)%>" name="<%=rs.getMetaData().getColumnName(i)%>" readonly/>
        </td>
        <%
        } else {
        %>
        <td><input value="<%=rs.getString(i)%>" name="<%=rs.getMetaData().getColumnName(i)%>"/></td>
        <%
                }
            }
        %>
        </form>
    </tr>
    <%
        }
    %>
</table>

</body>
</html>
